package com.gitee.limaozhi.socket.lesson03.example4;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hzlimaozhi
 * @date 2019/08/08 08:55
 */
public class HttpRequest {

    // 第一行
    private String method;
    private String uri;
    private String version;

    // 头部行
    private Map<String, String> headers = new HashMap<>();

    // 空行

    // 主体
    private String content;

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public void addHeader(String key, String value) {
        headers.put(key, value);
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isKeepAlive() {
        String keepAlive = headers.get("Connection");
        if ("keep-alive".equalsIgnoreCase(keepAlive)) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "HttpRequest{" +
                "method=" + method +
                ", uri=" + uri +
                ", version=" + version +
                ", headers=" + headers +
                ", content=" + content +
                '}';
    }

}
